<template>
  <div>
    <el-dialog
      title="分配角色权限"
      :visible.sync="dialogVisible"
      width="30%"
      :close-on-press-escape="false"
      :close-on-click-modal="false"
      :show-close="false"
    >
      <el-checkbox-group v-model="checkList">
        <el-checkbox v-for="item in roleList" :key="item.id" :label="item.id">
          {{ item.name }}
        </el-checkbox>
      </el-checkbox-group>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" size="small" @click="enterFn">确定</el-button>
        <el-button size="small" @click="cancelFn">取消</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: 'AssignRole',
  props: {
    showDia: {
      type: Boolean,
      default: false
    },
    roleList: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {
      dialogVisible: false,
      checkList: []
    }
  },

  watch: {
    showDia(newVal) {
      this.dialogVisible = newVal
    }
  },

  methods: {
    // 确认按钮
    enterFn() {
      this.$emit('assignRolesEv', this.checkList)
      this.$emit('update:showDia', false)
    },

    // 取消按钮
    cancelFn() {
      this.$emit('update:showDia', false)
    }
  }
}
</script>

<style lang="scss" scoped>
.footer {
  margin-top: 30px;
}
.dialog-footer {
  display: flex;
  justify-content: center;
}
</style>
